package com.zhongke.cotrun.service.impl;

import com.zhongke.cotrun.mapper.*;
import com.zhongke.cotrun.model.pojo.CompanyInfoVo;
import com.zhongke.cotrun.model.pojo.UserInfo;
import com.zhongke.cotrun.model.pojo.UserInfoExpert;
import com.zhongke.cotrun.service.ResearchService;
import com.zhongke.cotrun.service.UserAdminService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserAdminServiceImpl implements UserAdminService {
    @Autowired
    ExpertInfoMapper expertInfoMapper;
    @Autowired
    FacilitatorMapper facilitatorMapper;
    @Autowired
    CompanyInfoMapper companyInfoMapper;
    @Autowired
    UserInfoMapper userInfoMapper;
    @Autowired
    RegionMapper regionMapper;
    @Autowired
    ResearchService researchService;

    @Override
    public <T> T selecInformation(Integer type, Integer id) {
        switch (type) {
            case 1:
                UserInfo userInfo = userInfoMapper.selectUserInfoById(id);
                userInfo.setProvinceName(userInfo.getProvince());
                userInfo.setCityName(userInfo.getCity());
                return (T) userInfo;
            case 2:
                CompanyInfoVo companyInfoVo = companyInfoMapper.selectCompanyInfoByUserId(id);
                companyInfoVo.setProvinceName(getRegionName(companyInfoVo.getProvince()==null?null:companyInfoVo.getProvince().toString()));
                companyInfoVo.setCityName(getRegionName(companyInfoVo.getCity()==null?null:companyInfoVo.getCity().toString()));
                return (T) companyInfoVo;
            case 3:
                UserInfoExpert infoExpert = expertInfoMapper.selectExpertInfoByUserId(id);
                infoExpert.setProvinceName(getRegionName(infoExpert.getProvince()));
                infoExpert.setCityName(getRegionName(infoExpert.getCity()));
                infoExpert.setResearchArea(researchService.selectResearch(infoExpert.getResearchArea(), ","));
                return (T) infoExpert;
        }
        return null;
    }
    public String getRegionName(String regionId) {
        if (StringUtils.isNotEmpty(regionId))
            return regionMapper.selectByPrimaryKey(Integer.valueOf(regionId)).getName();
        return null;
    }
}
